<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>撞破南墙找西墙</title>
    <link href="https://cdn.staticfile.org/twitter-bootstrap/5.1.1/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.staticfile.org/twitter-bootstrap/5.1.1/js/bootstrap.bundle.min.js"></script>
    <link rel="stylesheet" type="text/css" href="/static/s.css">
    <link rel="icon" href="{{ url_for('static', filename='favicon.ico') }}" type="image/x-icon">
    <script language="JavaScript">
        var now_file_id = 1;
    </script>
</head>
<body>

{% include '_nav_index.html' %}

<br><br>

{% for message in get_flashed_messages(with_categories=True) %}
<div class="container">
    <div class="alert alert-{{ message[0] }}">
        {{ message[1]|safe }}
    </div>
</div>
{% endfor %}

<br>
<div class="container">
    <div class="row">
        <div class="col-md-12">
            <h2>发布图集</h2>
            <form action="" , method="post" enctype="multipart/form-data">
                <div class="mb-3 mt-3">
                    <textarea class="form-control" rows="5" id="comment" name="content" style="width: 100%; height: 400px;"
                              maxlength="80" required></textarea>
                </div>

                <button type="submit" class="btn btn-primary btn-major">发布
                </button>

                <!--点击添加按钮只弹出模态框，不执行其它动作-->
                <button type="button" class="btn btn-dark" data-bs-toggle="modal" data-bs-target="#uploadImgModal">
                    添加图片
                </button>

                <!-- 上传图片模态框 -->
                <div class="modal fade" id="uploadImgModal" data-bs-keyboard="false" tabindex="-1"
                     aria-labelledby="staticBackdropLabel" aria-hidden="true">
                    <div class="modal-dialog modal-dialog-centered">
                        <div class="modal-content">
                            <div class="modal-header">
                                <h5 class="modal-title" id="updateImgModal-staticBackdropLabel">上传图片</h5>
                                <button type="button" class="btn-close" data-bs-dismiss="modal"
                                        aria-label="Close"></button>
                            </div>
                            <div class="modal-body">
                                <div class="row mx-3">
                                    <!-- 图片类型：gif、png、jpeg -->
                                    <div id="files">
                                    <input type="file" id="img1" name="img1"
                                           class="form-control mb-2"
                                           accept="image/gif,image/png,image/jpeg"
                                           placeholder="支持jpg、png、gif格式图片">
                                    <button type="button" class="btn" id="add_btn" onclick="add_img()">添加更多图片</button>
                                    </div>
                                    <span class="text-secondary text-opacity-50">
                        支持jpg、png、gif格式图片
                    </span>
                                </div>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-major" data-bs-dismiss="modal">确定</button>
                            </div>
                        </div>
                    </div>
                </div>


                <!--        <div class="input-group">-->
                <!--            <label class="input-group-text">添加图片</label>-->
                <!--            <input type="file" class="form-control" id="img" aria-describedby="inputGroupFileAddon04"-->
                <!--                   aria-label="Upload" name="img">-->
                <!--        </div>-->
            </form>
            <br><br><br><br>
        </div>
    </div>
</div>

<script language="JavaScript">
    function add_img() {
        now_file_id ++;
        var container = document.getElementById('files');
        var btn = document.getElementById('add_btn');
        btn.remove();
        var input = document.createElement("input");
        input.type = "file";
        input.id = "img" + now_file_id.toString();
        input.name = "img" + now_file_id.toString();
        input.className = "form-control mb-2";
        input.accept = "image/gif,image/png,image/jpeg";
        input.placeholder = "支持jpg、png、gif格式图片";
        container.appendChild(input);
        var new_btn = document.createElement("button");
        new_btn.type = "btn";
        new_btn.className = "btn";
        new_btn.id = "add_btn";
        new_btn.onclick = add_img;
        new_btn.innerHTML = "添加更多图片";
        container.appendChild(new_btn);
    }

    function del_img() {
        var input = document.getElementById('img' + now_file_id.toString());
        input.remove;
        now_file_id --;
    }
</script>


</body>
</html>